package com.android.dopewars;

public class Drug {
	public Drug(String name, double likelihood, int base_price, int variance, int cutoff, boolean outlier_low, boolean outlier_high, double outlier_mult) {
		name_ = name;
		likelihood_ = likelihood;
		base_price_ = base_price;
		variance_ = variance;
		cutoff_ = cutoff;
		outlier_high_ = outlier_high;
		outlier_low_ = outlier_low;
		outlier_mult_ = outlier_mult;
		current_price_ = base_price;
	}
	
	public String name() { return name_; }
	public boolean present() { return (Global.rand_gen_.nextDouble() > likelihood_); }
	
	public int currentPrice() {
		return current_price_;
	}
	public void setNewPrice(int days_since_location) {
		int base_price = (int)(base_price_ - cutoff_ + Global.rand_gen_.nextDouble() * 2.0 * cutoff_);
		//int base_price = (int)(base_price_ + Global.rand_gen_.nextGaussian() * variance_);
		if (base_price > base_price_ + cutoff_) {
			base_price = base_price_ + cutoff_;
		}
		if (base_price < base_price_ - cutoff_) {
			base_price = base_price_ - cutoff_;
		}
		double outlier_probability = 0.15;
		if (days_since_location < 3) {
			outlier_probability -= 0.07;
		}
		if (days_since_location > 5) {
			outlier_probability += 0.07;
		}
		if (days_since_location > 8) {
			outlier_probability += 0.07;
		}
		if (days_since_location > 12) {
			outlier_probability += 0.07;
		}
		if (outlier_high_) {
			if (Global.rand_gen_.nextDouble() < outlier_probability) {
				base_price = (int)(base_price * outlier_mult_);
				Global.ui_messages_.add(name_ + " is being bought at unusually high prices!");
			}
		} else if (outlier_low_) {
			if (Global.rand_gen_.nextDouble() < outlier_probability) {
				base_price = (int)(base_price / outlier_mult_);
				if (base_price < 1) {
					base_price = 1;
				}
				Global.ui_messages_.add(name_ + " is being bought at unusually low prices!");
			}
		}
		current_price_ = base_price;
	}
	
	String name_;
	double likelihood_;
	int base_price_;
	int variance_;
	int cutoff_;
	boolean outlier_high_;
	boolean outlier_low_;
	double outlier_mult_;
	
	int current_price_;
}
